package com.shuoren.roomtemperaturecloud.controller;


import com.shuoren.roomtemperaturecloud.entity.ReturnJson;
import com.shuoren.roomtemperaturecloud.entity.SystemUser;
import com.shuoren.roomtemperaturecloud.service.UserService;
import com.shuoren.roomtemperaturecloud.util.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @Author: chenkai
 * @Date: 2018/12/26 14:57
 */
@Controller
public class UserController {
    private final static Logger logger = LoggerFactory.getLogger(UserController.class);
    @Autowired
    private UserService userService;

    @ResponseBody
    @GetMapping(value = "/save")
    public ReturnJson save(String createName, String pwd, String phone) {
        try {
            SystemUser user = new SystemUser();
            user.setCreatename(createName);
            user.setPassword(pwd);
            user.setMobilephone(phone);
            logger.info("日志日志");
            userService.save(user);
            return new ReturnJson(Constant.Result.SUCCESS_CODE, Constant.Result.SUCCESS_TOAST);
        } catch (Exception e) {
            e.printStackTrace();
            return new ReturnJson(Constant.Result.FAIL_CODE, Constant.Result.FAIL_TOAST, "");
        }
    }
}
